<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>employee_list</title>
    <link rel="stylesheet" th:href="@{/static/css/index.css}">
</head>
<body>
<div id="app">

    <table>
        <tr>
            <th colspan="5">employee_list</th>
        </tr>
        <tr>
            <th>id</th>
            <th>lastName</th>
            <th>email</th>
            <th>gender</th>
            <th>options(<a th:href="@{/to/add}">add</a>)</th>
        </tr>
        <tr th:each="employee : ${allEmployee}">
            <td th:text="${employee.id}"></td>
            <td th:text="${employee.lastName}"></td>
            <td th:text="${employee.email}"></td>
            <td th:text="${employee.gender}"></td>
            <td>
                <a @click="deleteEmployee"
                   th:href="@{'/employee/' + ${employee.id}}">delete</a>
                <a th:href="@{'/employee/' + ${employee.id}}">update</a>
            </td>
        </tr>
    </table>

    <form  id="delete_form" method="post">
        <input type="hidden" name="_method" value="delete">
    </form>

</div>


<script type="text/javascript" th:src="@{/static/js/vue.js}"></script>
<script type="text/javascript">
    var vue = new Vue({
        el:"#app",
        methods:{
//event表示当前事件
            deleteEmployee:function (event) {
//通过id获取表单标签
                var delete_form = document.getElementById("delete_form");
//将触发事件的超链接的href属性为表单的action属性赋值
                delete_form.action = event.target.href;
//提交表单
                delete_form.submit();
//阻止超链接的默认跳转行为
                event.preventDefault();
            }
        }
    });

</script>
</body>
</html>